package com.biz.sku.controller;

import com.netflix.hystrix.contrib.javanica.annotation.*;
import lombok.extern.slf4j.*;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author liuxi
 * @Date 2024/5/18
 **/
@RestController
@Slf4j
public class SkuController {

    @GetMapping("/test")
    public String test() {
        return "Hello World";
    }


    @GetMapping("/testTimeout")
    public String testTimeout() throws InterruptedException {
        Thread.sleep(3000);
        return "testTimeout";
    }

    @GetMapping("/testHystrix")
    public String testHystrix() {
        return "testHystrix";
    }

    /**
     * 提供方服务降级
     * 3秒后返回
     */
    @GetMapping("/testHystrixTimeout")
    @HystrixCommand(fallbackMethod = "testHystrixHandler", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")
    })
    public String testHystrixTimeout() throws InterruptedException {
        Thread.sleep(5000);
        return "testHystrixTimeout";
    }

    public String testHystrixHandler() {
        return "接口降级";
    }

}
